/*
 * @(#)org.example.netty.simple 2020/3/31/0031
 *
 * Copy Right@ 人人译视界
 */


package org.example.netty.simple;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * <pre>
 * @author tuwei
 *
 * @version 0.9
 *
 * 修改版本: 0.9
 * 修改日期: 2020/3/31/0031
 * 修改人 :  tuwei
 * 修改说明: 初步完成
 * 复审人 ：
 * </pre>
 */
public class NettyClient {
	public static void main(String[] args) throws InterruptedException {

		// 客户端需要一个事件循环组
		EventLoopGroup eventLoopGroup = new NioEventLoopGroup();

		try {
			// 创建客户端的启动对象
			Bootstrap bootstrap = new Bootstrap();
			bootstrap.group(eventLoopGroup)// 设置线程组
					.channel(NioSocketChannel.class)//设置客户端通道实现类
					.handler(new ChannelInitializer<SocketChannel>() {
						@Override
						protected void initChannel(SocketChannel socketChannel) throws Exception {
							socketChannel.pipeline().addLast(new NettyClientHandler());
						}
					});
			System.out.println("客户端 is ok");
			ChannelFuture channelFuture = bootstrap.connect("127.0.0.1", 6668).sync();
			channelFuture.channel().closeFuture().sync();
		} finally {
			eventLoopGroup.shutdownGracefully();
		}
	}
}
